--#include "data\config\misc\ChangeJobConfig.lua" once

function OnChangeJobHandle( sysarg, msgid, packet, isTest )
	local jobLevel =  Actor.getIntProperty(sysarg,PROP_ACTOR_JOB_LEVEL)
	if jobLevel > 0 then
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.ChangeJob001, ttFlyTip)
		return
	end

	if not isTest then
		for i,v in ipairs(ChangeJobConfig.TaskAchieveId) do
			if not Actor.isAchieveFinished(sysarg, v) then
				Actor.sendTipmsg(sysarg, Lang.ScriptTips.ChangeJob002, ttFlyTip)
				return 
			end	
		end
	end
	
	local actorId 	= Actor.getActorId( sysarg )
  	local nActorJob = Actor.getIntProperty(sysarg, PROP_ACTOR_VOCATION)
    local nActorSex = Actor.getIntProperty(sysarg, PROP_ACTOR_SEX)
	Awards.GiveToMailById( actorId, ChangeJobConfig.Awards, Lang.ScriptTips.ChangeJob003, Lang.ScriptTips.ChangeJob004, LogIds.ChangeJobLogId, Lang.LogTips.ChangeJobLogId,nActorJob, nActorSex)
	Actor.setUIntProperty(sysarg, PROP_ACTOR_JOB_LEVEL, 1)
	Actor.collectOperate(sysarg,0) -- 重新计算角色属性

	local sysMsg = string.format(Lang.ScriptTips.ChangeJob005, Actor.getName(sysarg))
    System.broadcastTipmsg(sysMsg, ttChatWindow + ttScreenCenter)
end


MiscsImplement.registerMsgHandler(LogicCmd.miscSys.sub.cChangeJobOp, OnChangeJobHandle)
